//
//  AcitivityDetailViewController.m
//  豆瓣(阿黄)
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "AcitivityDetailViewController.h"
#import "ActivityDetailView.h"
#import "ActivityList.h"
#import "UIImageView+WebCache.h"
#import "UserLoginViewController.h"

@interface AcitivityDetailViewController ()

@property (nonatomic, retain)ActivityDetailView *activityDV;

@property (nonatomic, retain)UIScrollView *myScroll;

@end

@implementation AcitivityDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //渲染
    UIImage *leftImage = [UIImage imageNamed:@"btn_nav_back.png"];
    leftImage = [leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIImage *rightImage = [UIImage imageNamed:@"btn_nav_share.png"];
    rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftImage style:UIBarButtonItemStyleDone target:self action:@selector(leftButtonAction:)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:rightImage style:UIBarButtonItemStyleDone target:self action:@selector(rightButtonAction:)];
    
    self.myScroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view addSubview:self.myScroll];
    [self.myScroll release];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.activityDV = [[ActivityDetailView alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    [self.myScroll addSubview:self.activityDV];
    
    
    ActivityList *activityL = [self.bigArray objectAtIndex:self.detailIndex.row];
    self.activityDV.titleLabel.text = activityL.title;
    self.activityDV.timeLabel1.text = [activityL.begin_time substringFromIndex:5];
    self.activityDV.timeLabel2.text = [activityL.end_time substringFromIndex:5];
    self.activityDV.typeLabel.text = activityL.category_name;
    self.activityDV.addressLabel.text = activityL.address;
    self.activityDV.content.text = activityL.content;
    self.activityDV.sponsorLabel.text = self.ownerName;
    
    self.navigationItem.title = self.activityDV.titleLabel.text;
    
    NSURL *url = [NSURL URLWithString:activityL.image_hlarge];
    [self.activityDV.picImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeHoderImage.png"]];
    
#pragma mark -- 计算内容高度第二步:计算label高度
    CGFloat height = [ActivityDetailView heightForContent:self.activityDV.content.text];
    NSLog(@"%@", self.activityDV.content.text);
    CGRect tempFrame = self.activityDV.content.frame;
    tempFrame.size.height = height;
    self.activityDV.content.frame = tempFrame;
    
    CGFloat height1 = [ActivityDetailView heightForContent:activityL.content] + 340;
    self.myScroll.contentSize = CGSizeMake(375, height1);
    
    
}

- (void)leftButtonAction:(UIBarButtonItem *)btn{

    [self.navigationController popViewControllerAnimated:1];
}


- (void)rightButtonAction:(UIBarButtonItem *)btn{
    
    UserLoginViewController *loginVC = [[UserLoginViewController alloc] init];
    UINavigationController *loginNavi = [[UINavigationController alloc] initWithRootViewController:loginVC];
    
    [self presentViewController:loginNavi animated:1 completion:^{
        
        
    }];
    
    [loginNavi release];
    [loginVC release];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
